﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Rabbit.Logic;
using RabbitManage.Code;

namespace RabbitManage.UI
{
    public partial class ShipRuleAdd : System.Web.UI.Page
    {
        protected List<ProvinceCity> list;
        protected string provinceAfar = CityData.Afar;

        protected List<Tuple<string, decimal>> ruleList;
        protected Dictionary<string,decimal> dic; 

        protected string stragegyName = string.Empty;
        protected decimal cost = 0;
        protected decimal greaterThan = 0;
        protected Address address = new Address();

        protected void Page_Load(object sender, EventArgs e)
        {
            list = CityData.GetMainlandData();
            //provinceRepeater.DataSource = list;
            //provinceRepeater.DataBind();

            HttpCookie cookie = Request.Cookies[Constant.CookieName];
            string shopId = cookie.Values[Constant.CookieUid];
            ShipRule rule = RabbitUse.GetShipRuleByShopId(Db.Store, shopId);
            if (rule == null)
            {
                //ruleList=new List<Tuple<string, decimal>>();
                //rule = new ShipRule();
                //rule.ShopId = shopId;

                //Dictionary<string, decimal> rules = new Dictionary<string, decimal>();
                //foreach (string province in item.ProvinceList)
                //{
                //    rules[province] = item.Cost;
                //}
                //rule.Rules = rules;
                dic=new Dictionary<string, decimal>();
                foreach (var provinceCity in list)
                {
                    dic[provinceCity.Name] = 0m;
                }
            }
            else
            {
                //foreach (var province in rule.Rules)
                //{
                //    Tuple<string , decimal> tuple=new Tuple<string, decimal>(province.Key,province.Value);
                //    ruleList.Add(tuple);
                //}
                dic = rule.Rules;
            }
            //ruleRepeater.DataSource = dic;
            //ruleRepeater.DataBind();
            costRepeater.DataSource = dic;
            costRepeater.DataBind();
        }
    }
}